<template>
  <div>
    <tableComponents
      :pagination="{ currentPage, pageSize, total: list.all_num }"
      @handleCurrentChange="handleCurrentChange"
      @handleSizeChange="handleSizeChange"
      @sendUserSearch="getSearch"
      :searchData="userSearchData"
      :isHaveExport="false"
      @toAdd="toStockList"
    >
      <template v-slot:searchBottom>
        <el-form class="search_prod search_prod1" label-width="94px">
          <el-form-item label="退货类型">
            <el-row class="tl mar_bottom_15">
              <el-radio-group
                v-model="oid_cn"
                size="small"
                class="tl money-group"
                @change="getNewsAll(searchAll)"
              >
                <el-radio-button label=""> 全部 </el-radio-button>
                <el-radio-button label="TH"> 退货 </el-radio-button>
                <el-radio-button label="DB"> 调拨 </el-radio-button>
                <el-radio-button label="order"> 订单 </el-radio-button>
              </el-radio-group>
            </el-row>
          </el-form-item>
        </el-form>
      </template>
      <template v-slot:table>
        <el-table
          ref="multipleTable"
          :data="list.data"
          v-loading="loading"
          header-row-class-name="head_color"
          stripe
          tooltip-effect="dark"
          style="width: 99.9%"
        >
          <el-table-column label="订单号" min-width="140">
            <template slot-scope="scope">
              {{ scope.row.oid || "----" }}
            </template>
          </el-table-column>

          <el-table-column label="商品" min-width="250">
            <template slot-scope="scope">
              <div class="user_table">
                <p>
                  <span>商品名称：</span>
                  <small>{{ scope.row.title || "----" }}</small>
                </p>
                <p v-if="scope.row.sku_cn">
                  <span>规格：</span>
                  <small>{{ scope.row.sku_cn || "----" }}</small>
                </p>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="类型" min-width="120">
            <template slot-scope="scope">
              {{ scope.row.extract_id > 0 ? `分店` : `总部` }}
              <span v-if="scope.row.extract_id > 0">
                ：{{ scope.row.extract_cn || "----" }}
              </span>
            </template>
          </el-table-column>

          <el-table-column label="库存" min-width="160">
            <template slot-scope="scope">
              <div class="user_table">
                <p>
                  <span>数量：</span>
                  <small>
                    {{
                      scope.row.types == 1
                        ? "+"
                        : scope.row.types == 2
                        ? "-"
                        : ""
                    }}{{ scope.row.stock }}
                  </small>
                </p>
                <p>
                  <span>总金额：</span>
                  <small>
                    {{ scope.row.price | keepTwoNum }}
                  </small>
                </p>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="记录" min-width="140">
            <template slot-scope="scope">
              <div class="user_table">
                <p>
                  <span>时间：</span>
                  <small>{{ scope.row.created_time | getTimeFormat }}</small>
                </p>
                <p>
                  <span>操作员：</span>
                  <small>{{ scope.row.operator || "----" }}</small>
                </p>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="备注" min-width="140">
            <template slot-scope="scope">
              {{ scope.row.remark || "----" }}
            </template>
          </el-table-column>
        </el-table>
      </template>
    </tableComponents>
  </div>
</template>

<script>
import { returnStockSearchData } from "@/assets/js/searchData/searchData"; //引入搜索的数据
export default {
  data() {
    return {
      userSearchData: returnStockSearchData,
      searchAll: {},
      loading: false,
      list: [],
      pageSize: 10,
      currentPage: 1,
      oid_cn: "",
    };
  },
  components: {},
  created() {
    this.getNewsAll();
  },
  methods: {
    toStockList() {
      // this.$store.commit("addbreadcrumbs", {
      //   title: "进货明细",
      //   url: `/index/shop/product_stock?types=1`,
      // });
      this.$router.push({
        path: "/index/shop/refund_stock",
      });
    },
    getSearch(obj) {
      this.searchAll = obj;
      this.getNewsAll(obj);
    },
    handleSizeChange(val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getNewsAll(params);
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      var params = this.searchAll;
      params.page = val;
      params.page_size = this.pageSize;
      this.getNewsAll(params);
    },
    getNewsAll(data) {
      this.loading = true;
      var params = {};
      data = data || {};
      params = data;
      params.types = 2;
      params.is_extract = 0;

      params.oid_cn = this.oid_cn;

      this.$api.getShops.product_stock_lists(params).then((res) => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
    imgError(item) {
      if (!item) {
        return require("@/assets/img/default_head.png");
      }
      return item;
    },
  },
};
</script>

<style>
</style>